package com.rb.ll;

import java.util.ArrayList;

import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.ViewSwitcher;
import android.app.Activity;
import android.gesture.GestureOverlayView;

import android.view.GestureDetector.OnGestureListener;
import android.view.GestureDetector;

import android.os.Bundle;
import android.provider.UserDictionary.Words;

public class StartActivity extends Activity implements OnGestureListener {
    /** Called when the activity is first created. */
	
	class Rec {
		String from;
		String to;
		public void setFrom(String sfrom){
			from = sfrom;
		}
		
		public void setTo (String sto){
			to = sto;
		}
		
		public String getFrom(){
			return from;
		}
		public String getTo () {
			return to;
		}
	}
	
	private int idWord = 0;
	ArrayList <Rec> words = new ArrayList <Rec>();
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        
        Rec rec = new Rec();
        rec.setFrom("Home");
        rec.setTo("Dom");
        words.add(rec);
        
        rec = new Rec();
        rec.setFrom("Family");
        rec.setTo("Rodzina");
        words.add(rec);
        
        gestureScanner = new GestureDetector(this);
        
        setContentView(R.layout.main);
        
        
        
        LinearLayout layout = (LinearLayout)this.findViewById(R.id.layout);
        
        layout.setBackgroundColor(android.graphics.Color.RED);
       // ViewSwitcher switcher = (ViewSwitcher)this.findViewById(R.id.switcher);
        
       // switcher.setBackgroundColor(android.R.color.background_light);
        
         /*
        
        switcher.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                // Perform action on click
            	Log.i("OK","click");
            }
        });
       
        layout.setOnTouchListener(new OnTouchListener() {
        //switcher.setOnClickListener(new OnTouchListener() {
        	
			public boolean onTouch(View v, MotionEvent event) {
				//LinearLayout.requestFocus();
				
				//switch (event) {
				//	case 
				//}
				//Log.i("OK","sdf : " + event);
				return true;
			}
        	
        	}
        		
        );
        */
        TextView from = ( TextView ) this.findViewById(R.id.from);
        //from.setText("OK");
        
        
        
        TextView to = ( TextView ) this.findViewById(R.id.to);;
        //to.setText("O3");
        
        /*
        switcher.addView(text);
        
        switcher.addView(text2);
        
        switcher.showNext(); */
        
    }
    
    
    
 
    
    

    private GestureDetector gestureScanner;
    
    @Override
    public boolean onTouchEvent(MotionEvent me) {
    	
    	Log.i("OK","onTouchEvent : "+me);
        return gestureScanner.onTouchEvent(me);
        
    }
   
    //@Override
    public boolean onDown(MotionEvent e) {
    	Log.i("OK","onDown");
        return true;
    }

    public void onLongPress(MotionEvent e) {
    	showTranslate();
    }
 
    //@Override
    public void onShowPress(MotionEvent e) {
        //viewA.setText("-" + "SHOW PRESS" + "-");
    	Log.i("OK","onShowPress");
    }    
    
    private void showTranslate () {
    	Log.i("OKK","showTranslate");
    	
    	TextView to = ( TextView ) this.findViewById(R.id.to);;
    	to.setText("03");
        //to.setVisibility(View.VISIBLE);
    }
   
    //@Override
    public boolean onSingleTapUp(MotionEvent e) {
        //viewA.setText("-" + "SINGLE TAP UP" + "-");
    	showTranslate();
    	
    	//extends Activity implements OnGestureListener
        return true;
    }

    


	public boolean onFling(MotionEvent arg0, MotionEvent arg1, float arg2,
			float arg3) {
		// TODO Auto-generated method stub
		
		Log.i("OKR","onFling ["+arg2+ "]");
		
		if (arg2>0) {
			if (idWord>0) {
				idWord = idWord - 1;
			} else {
				idWord = words.size()-1;
			}
			
		} else {
			if (idWord<words.size()-1) {
				idWord = idWord + 1;
			} else {
				idWord = 0;
			}
		}
		
		Rec rec = words.get(idWord);
		
        TextView from = ( TextView ) this.findViewById(R.id.from);
        from.setText( rec.getFrom()  );
        
        
        
        TextView to = ( TextView ) this.findViewById(R.id.to);;
        to.setText("");
		
        //to.setVisibility(View.GONE);
        
		return false;
	}

	public boolean onScroll(MotionEvent arg0, MotionEvent arg1, float arg2,
			float arg3) {
		Log.i("OK","onScroll"+arg0);
		Log.i("OK","onScroll : "+arg1);
		// TODO Auto-generated method stub
		return false;
	}

}